local yizhuang = fk.CreateSkill {
  name = "th_yizhuang",
  max_turn_use_time = 1,
}

yizhuang:addEffect("active", {
  anim_type = "support",
  expand_pile = "th_nitori_xie",
  prompt = function(self, player, selected_cards, selected_targets)
    local target = "you"
    if Fk:currentRoom():getCurrent() == player then
      target = Fk:translate("anyone") .. Fk:translate("characters")
    end
    return "#th_yizhuang-invoke:::" .. target
  end,
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return #player:getPile("th_nitori_xie") > 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and player:getPileNameOfId(to_select) == "th_nitori_xie"
  end,
  target_filter = function(self, player, to_select, selected, cards)
    if #selected == 0 and #cards == 1 then
      if player.phase == Player.NotActive and to_select ~= player then
        return false
      end
      return #to_select:getAvailableEquipSlots(Fk:getCardById(cards[1]).sub_type) > 0
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card = Fk:getCardById(effect.cards[1])
    room:moveCardIntoEquip(target, card.id, yizhuang.name, true, player)
  end,
}, { check_skill_limit = true })

yizhuang:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("th_yizhuang") and #player:getPile("th_nitori_xie") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = "you"
    if Fk:currentRoom():getCurrent() == player then
      to = Fk:translate("anyone") .. Fk:translate("characters")
    end
    local _, ret = room:askToUseActiveSkill(player, {
      skill_name = "th_yizhuang",
      -- prompt = "#th_yizhuang-invoke:::" .. to,
      cancelable = true,
      skip = true
    })
    if ret then
      event:setCostData(self, { tos = ret.targets, cards = ret.cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local dat = event:getCostData(self)
    Fk.skills[yizhuang.name]:onUse(player.room, SkillUseData:new {
      from = player,
      cards = dat.cards,
      tos = dat.tos,
    })
  end
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["th_yizhuang"] = "易装",
  [":th_yizhuang"] = "每回合限一次，出牌阶段或当你成为使用牌的目标后，你可以将一张“械”置入你的装备区（替换原装备），若此时是你的回合，改为置入任意角色的装备区。",

  ["#th_yizhuang-invoke"] = "易装：你可以将一张“械”置入%arg的装备区",

  ["th_nitori_xie"] = "械",
}

return yizhuang